<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Calling another Service Component</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="sca.examples.proxies.html">Obtaining a proxy for another Service Component</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="sca.examples.nonscascript.html">Locating and calling services from a script which is not an
   SCA Component</a></div>
 <div class="up"><a href="sca.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="sca.examples.calling" class="section">
  <h2 class="title"> Calling another Service Component </h2>
  
  <p class="para">
   The ConvertedStockQuote example also calls the proxies for
   the two components to which it refers. 
  </p>
  
  <p class="para">
   <div class="example" id="example-5182">
    <p><strong>Example #1  Calling services </strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$quote&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">stock_quote</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getQuote</span><span style="color: #007700">(</span><span style="color: #0000BB">$ticker</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$rate&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exchange_rate</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getRate</span><span style="color: #007700">(</span><span style="color: #0000BB">$currency</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  
  <p class="para"> 
   The call to the StockQuote service is a call to a local service;
   the call to the ExchangeRate service is a call to a remote service.
   Note that the way the call is made looks the same regardless of
   whether the call is to a local service or a remote one. 
  </p>

  <p class="para"> 
   The proxies which have been injected ensure that the way calls
   to components look and behave are the same way regardless of whether
   they are to a local or remote service, so that components are not
   sensitive to whether a call is to a local or a remote service. For
   example, the proxy for a local service takes copies of the arguments
   and passes only those copies, to ensure that calls are made to be
   pass-by-value, as they would be for a remote call. Also, the proxy
   for a remote service takes the arguments from a positional
   parameter list and ensures they are packaged properly in a SOAP
   request and converted back to a positional parameter list at the far
   end. 
  </p>
  
  <p class="para"> 
   In the example above, the
   
   <var class="varname"><var class="varname">$ticker</var></var> and
   
   <var class="varname"><var class="varname">$currency</var></var> are clearly PHP scalar types.
   Components can pass the PHP scalar types string, integer, float and
   boolean, but data structures on service calls are always passed as
   Service Data Objects (SDOs). A later section describes how a
   component can create an SDO to pass on a local or Web service call, or
   how a component can create an SDO to return. The PHP SDO project
   documentation describes how to work with the SDO APIs (see
   <a href="ref.sdo.html" class="link">the SDO pages</a>).
  </p>
  
 </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="sca.examples.proxies.html">Obtaining a proxy for another Service Component</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="sca.examples.nonscascript.html">Locating and calling services from a script which is not an
   SCA Component</a></div>
 <div class="up"><a href="sca.examples.html">范例</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
